﻿using Autofac.Core;
using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Interface.SheepFileModelInterface;
using IntelligentAgriculture.WebAPI.Application.Command.SheepAblactationCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Asn1.Mozilla;
using System.Diagnostics;
using Yitter.IdGenerator;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 种母断奶控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepAblactationController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数。
        /// </summary>
        /// <param name="mediator">用于中介调解模式的中介器实例，用于处理请求和发送命令。</param>
        public SheepAblactationController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 获取档案表母羊在哺乳的耳号列表
        /// </summary>
        /// <returns>包含母羊在哺乳状态的耳号信息的列表</returns>
        [HttpGet]
        public async Task<Results<List<Eartag>>> GetEweEarTagsFromSheepFile()
        {
            var command = new GetEweEarTagsFromSheepFileCommand();
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取羊只的档案
        /// </summary>
        /// <param name="earTagNumber"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<List<Sheepfilemodel>>> GetBuildByEar(string earTagNumber)
        {
            var command = new GetBuildByEarCommand(earTagNumber);
            return await _mediator.Send(command);
        }
        #region 废弃代码
        /// <summary>
        /// 获取种母分娩的列表
        /// </summary>
        /// <returns></returns>
        //[HttpGet]
        //public async Task<Results<List<Childbirth>>> Handle()
        //{
        //    var command = new GetChildBirthIdCommand();
        //    return await _mediator.Send(command);
        //}
        #endregion
        /// <summary>
        ///  获取种母断奶的列表
        /// </summary>
        /// <param name="input">入参</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PageOutput<SheepAblactationOutput>>> GetSheepAblactation(SheepAblactationInput input)
        {
            return await _mediator.Send(new GetSheepAblactationCommand(input));
        }
        /// <summary>
        /// 新增种母断奶
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddSheepAblactation([FromBody] List<Sheepablactation> input)
        {
            var command = new AddSheepAblactationCommand(input);
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除种母断奶
        /// </summary>
        /// <param name="userId"> 用户Id </param>
        /// <param name="ids"> 种母断奶Id 列表 </param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Results<int>> DelSheepAblacations(DelSheepAblacationsCommand input)
        {
            var command = new DelSheepAblacationsCommand(input.userId, input.ids);
            return await _mediator.Send(command);
        }
    }
}
